package update

import (
	"context"

	"server_1.0/api/internal/svc"
	"server_1.0/api/internal/types"
	"server_1.0/service/college/college"
	"server_1.0/util"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateCollegeLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUpdateCollegeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateCollegeLogic {
	return &UpdateCollegeLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpdateCollegeLogic) UpdateCollege(req *types.ColUpdateReq) (resp *types.PostReps, err error) {
	code := util.Success
	Msg := "修改成功"
	Reps, _ := l.svcCtx.CollegeRpc.Update(l.ctx, &college.UpdateReq{
		No:   req.Cno,
		Name: req.Cname,
	})
	if Reps.Count == 0 {
		code = util.NoFoundError
		Msg = "无记录"
	}
	return &types.PostReps{
		Code: code,
		Msg:  Msg,
		Data: map[string]interface{}{
			"res": Reps.QRs,
		},
	}, nil
}
